package com.tjshop.android.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tjshop.android.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tjshop.android.model.Category;
import com.tjshop.android.model.tj.json.Banner;
import com.tjshop.android.model.tj.json.HomeCategory;
import com.tjshop.android.util.ImageLoaderUtils;

import java.util.List;

/**
 * Created by Administrator on 2014/10/21.
 */
public class CategoryAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	HomeCategory cList;
	private Context mContext;

	public CategoryAdapter(Context context, HomeCategory clist,
			LayoutInflater inflater) {
		this.inflater = inflater;
		cList = clist;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return cList.getItems().size();
	}

	@Override
	public Object getItem(int i) {
		return cList.getItems().get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		if (view == null) {
			view = inflater.inflate(
					R.layout.inc_activity_main_fragment_home_categories_item,
					null);
		}
		ImageView img = (ImageView) view
				.findViewById(R.id.fragment_home_categories_item_image);
		if(i == 6){
			img.setImageResource(R.drawable.class_order);
		}else if(i == 7){
			img.setImageResource(R.drawable.class_all);
		}else{
			String thumbPath = cList.getItems().get(i).getPic();
			ImageLoaderUtils.getInstance(mContext).displayImage(thumbPath, img);
		}
		
			TextView text = (TextView) view
					.findViewById(R.id.fragment_home_categories_item_text);
			text.setText(cList.getItems().get(i).getCat_name());

		return view;
	}
}
